var username;

isRun();

async function isRun() {
	var flag = await send_Background({code: 'getLoginStatus'});
	if (flag) check_Login();
}

async function check_Login() {
	title();
	await getUserName();
}

async function getUserName() {
	while(true) {
		var username_dom = document.querySelectorAll('span[class="name"]')[0];
		if (username_dom) {
			username = username_dom.innerText.trim();
			var nickname_temp = await send_Background({code: 'getNickname'});
			var login_title_dom = await getElement('id', 'extend_login_title');
			login_title_dom.remove();
			login_succ(username == nickname_temp);
			if (username == nickname_temp) upCookies();
			break;
		}
		await delay(2);
	}
}

function upCookies() {
	send_Background({code: 'upCookies', url: 'https://baijiahao.baidu.com/*'});
}